package com.springcloud.util.model;

import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPCellEvent;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPTableEvent;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.dom4j.Element;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: TODO
 * @Create by: 123
 * @Date: 2021/11/22 17:03
 */

@Data
public class CellEventEnhance implements PdfPCellEvent {

    private List<PdfPCellEvent> cellEvents;

    public void addCellEvent(PdfPCellEvent tableEvent) {
        if (cellEvents == null) {
            this.cellEvents = new ArrayList<>();
        }
        cellEvents.add(tableEvent);
    }

    public void addCellEvent(Element tableEvent) {
        if (cellEvents == null) {
            this.cellEvents = new ArrayList<>();
        }
        // todo 构建table event
    }


    @Override
    public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
        if (CollectionUtils.isNotEmpty(cellEvents)) {
            for (PdfPCellEvent cellEvent : cellEvents) {
                cellEvent.cellLayout(cell, position, canvases);
            }
        }
    }
}

